package frontend.user;

import backend.DiseaseItem;
import javax.swing.*;
import java.awt.*;

public class DiseaseInfoPanel extends JPanel {
    private String getSafeValue(String value) {
        return (value != null && !value.isEmpty() && !value.equals("暂无数据"))
                ? value : "暂无数据";
    }

    public DiseaseInfoPanel(DiseaseItem item) {
        setLayout(new BorderLayout());

        if (item == null) {
            item = new DiseaseItem(); // 创建空对象
        }

        String symptomText;
        String treatmentText;
        String noticeText;

        symptomText = "症状：" + getSafeValue(item.Symptom()) + "\n发生部位：" + getSafeValue(item.Organ());
        treatmentText = "药物治疗：" + getSafeValue(item.Medication()) + "\n缓解方式：" + getSafeValue(item.Reliefmethod());
        noticeText = "饮食建议：" + getSafeValue(item.Diet()) + "\n影响程度：" + item.Impact() + "\n紧急程度：" + getSafeValue(item.Urgency());


        // 症状与发生部位（含图片）
        JPanel symptomAndImagePanel = new JPanel(new GridLayout(1, 2));
        JTextArea symptomTextArea = new JTextArea(symptomText);
        symptomTextArea.setEditable(false);
        symptomTextArea.setLineWrap(true);
        symptomTextArea.setWrapStyleWord(true);
        symptomAndImagePanel.add(new JScrollPane(symptomTextArea));

        JLabel imageLabel = new JLabel(new ImageIcon("path_to_image")); // 替换为实际的图片路径
        symptomAndImagePanel.add(imageLabel);

        // 治疗方法
        JTextArea treatmentTextArea = new JTextArea(treatmentText);
        treatmentTextArea.setEditable(false);
        treatmentTextArea.setLineWrap(true);
        treatmentTextArea.setWrapStyleWord(true);

        // 注意事项
        JTextArea noticeTextArea = new JTextArea(noticeText);
        noticeTextArea.setEditable(false);
        noticeTextArea.setLineWrap(true);
        noticeTextArea.setWrapStyleWord(true);

        // 组装组件
        add(symptomAndImagePanel, BorderLayout.NORTH);
        add(new JScrollPane(treatmentTextArea), BorderLayout.CENTER);
        add(new JScrollPane(noticeTextArea), BorderLayout.SOUTH);
    }
}
